package com.songlanyun.modules.applyareaagent.controller;

import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import com.songlanyun.modules.applyareaagent.entity.ApplyAreaAgentDTO;
import com.songlanyun.modules.applyareaagent.entity.ApplyAreaAgentEntity;
import com.songlanyun.modules.applyareaagent.service.ApplyAreaAgentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 申请区域代理
 *
 * @author lubo
 * @email sunlightcs@gmail.com
 * @date 2022-09-29 14:33:03
 */
@RestController
@RequestMapping("api/applyareaagent")
public class ApplyAreaAgentApiController extends AbstractApiController {
    @Autowired
    private ApplyAreaAgentService applyAreaAgentService;

    /**
     * 被锁定列表
     */
    @RequestMapping("/page")
    //@RequiresPermissions("applyareaagent:applyareaagent:list")
    public R page(@RequestParam Map<String, Object> params){
        PageUtils page = applyAreaAgentService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 我的申请
     */
    @GetMapping("/info")
    //@RequiresPermissions("applyareaagent:applyareaagent:info")
    public R info(){
		ApplyAreaAgentEntity applyAreaAgent = applyAreaAgentService.loadByUserId(getUserId(true));
        return R.ok().put("applyAreaAgent", applyAreaAgent);
    }

    /**
     * 申请区域代理
     */
    @PostMapping("/apply")
    //@RequiresPermissions("applyareaagent:applyareaagent:save")
    public R apply(@RequestBody ApplyAreaAgentDTO dto){
		applyAreaAgentService.apply(getUserId(true),dto);
        return R.ok();
    }
}
